﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_Ajax_test :NoTheme
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Pan.Log.WriteLog("来了");
        //...处理一些逻辑内容后接下来要返回数据给js
        string callback = Request.QueryString.Get("callback");
        string citycode = Request.QueryString.Get("citycode");
        string backjsondata = "({'productid':'16','productname':'220元团购四川旅游通票金熊猫贵宾卡（总价值5218元）','price':'220.0','oldprice':'5218.0','imagepath':'~/UploadFile/5_2010/e20fb7c0-5602-4114-af43-3937b940bbf8.jpg'})";
        //要将返回的数据封成json格式的字符串，具体的上百度上查下json的数据格式//简单的写法就是({'变量名':'变量值'})
        //多个的话写成({'变量名1':'变量值1','变量名2':'变量值2',.....})
        //这里callback变量一定要返回回去，并把已包装成JSON的格式({'usersex':'男'})的json字符串和callback一并返回


        System.Text.StringBuilder backJsonDates = new System.Text.StringBuilder();

       // Response.Write("var jimmy = {name:\"jimmy.yang\",email:\"jimmy.yang@163.com\"}");

        Pan.Log.WriteLog("获取到了" + citycode);
        if (string.IsNullOrEmpty(citycode))
            citycode = "guangzhou";//默认广州
        Tuan.Model.Products obj = (new Tuan.BLL.Products()).GetWebServiceModle(citycode);

        string formatStr;
        if (obj != null)
        {
            string leftpanle="<h3 style=\"font-size:12px; margin:0; padding:0;\">菠萝团--<a href=\"http://5151tuan.com\">5151tuan.com</a></h3><p style=\"font-size:12px; margin:0; padding:0;\">每天从广州数百万个商家中精挑细选出一款精品产品奉献给您,<font style=\"color:Red\" >快乐每一天 期待每一天</font></p>";
            formatStr = "({'productid':'" + obj.ProductID + "','productname':'" + obj.ProductName + "','price':'" + obj.NowPrice.ToString().TrimEnd('0').TrimEnd('.') + "','oldprice':'" + obj.OldPrice.ToString().TrimEnd('0').TrimEnd('.') + "','imagepath':'" + obj.ShowImage.TrimStart('~') + "','discount':'" + String.Format("{0:f1}", (obj.NowPrice / obj.OldPrice) * 10).TrimEnd('0').TrimEnd('.') + "','leftpanle':'"+leftpanle+"'})";
            Pan.Log.WriteLog(formatStr);
        }
        else
        {
            formatStr = "({})";
            Pan.Log.WriteLog("为null");
        }

        string mybackdata = callback + formatStr;
        Response.Write(mybackdata);
        Response.End();
    }
}
